import { Component, ElementRef, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { WebGLService } from 'src/app/services/webgl.service';

@Component({
    selector: 'hello-webgl',
    templateUrl: './hello-webgl.component.html',
    styleUrls: ['./hello-webgl.component.scss']
})
export class HelloWebGLComponent implements OnInit, AfterViewInit {
    @ViewChild('canvas') canvas: ElementRef;

    constructor(private webglService: WebGLService) { }

    ngOnInit() { }

    ngAfterViewInit () {
        this.init();
    }

    init () {
        const gl = this.webglService.getGLContext(this.canvas.nativeElement);

        gl.clearColor(0.0, 0.0, 0.0, 1.0);
        gl.clear(gl.COLOR_BUFFER_BIT);
    }
}